﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Pub;

namespace LZQXT.Test
{
    public class CTree
    {

        public String sIDCol = "ID";
        public String sName = "ClassName";
        public String sPreCol = "PreID";
        public String sTabName = "GSMA_P_Class";
        public String sTagID = "Target";
        public String sOrderID = "OrderID";

        private ADOTest ado1;

        public void fillTreeView(TreeView tv1, TreeNode node1)
        {
            try
            {
                ado1 = Program.fdb_tree.ado1;

                string PreID = "";
                if (node1 != null)
                    PreID = node1.Tag.ToString();
                if (PreID == null || PreID == "") PreID = "-1";
                string strSQL = "SELECT * FROM " + sTabName + " WHERE " + sPreCol + "=" + PreID + " Order By " + sOrderID;
                //CDebug.Send(strSQL);
                ado1.sel1(strSQL);
                foreach (DataRow dr in ado1.ds.Tables[0].Rows)
                {
                    TreeNodeII newNode = new TreeNodeII();

                    newNode.Text = dr[sName].ToString();
                    newNode.Tag = dr[sIDCol].ToString();
                    newNode.Target = dr[sTagID].ToString();
                    newNode.ImageIndex = 0;
                    newNode.SelectedImageIndex = 0;
                    newNode.PreID = PreID;
                    //newNode.Target = "iframeCenter";
                    //newNode.NavigateUrl = "../" + dr["Url"].ToString() + "?ClsID=" + newNode.Value;

                    string sID = dr[sIDCol].ToString();
                    fillTreeView(tv1, newNode);
                    if (newNode.Nodes.Count > 0)
                        newNode.ImageIndex = 0;
                    else
                        newNode.ImageIndex = 1;

                    if (node1 == null) tv1.Nodes.Add(newNode);
                    else node1.Nodes.Add(newNode);
                }
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
                CDebug.Send("生成树目录", ex.ToString());
            }

        }
    }

    public class TreeNodeII : TreeNode
    {
        public String Target = "";
        public String PreID = "";
    }
}